package com.Ajava1704.for定时线程池的使用;

import java.util.concurrent.ScheduledExecutorService;

/**
 * @类名: com.Ajava1704.for定时线程池的使用
 * @作者: lgt
 * @创建时间: 2020-02-11 20:26
 * @描述:
 **/
public class ForConnRunable implements Runnable{

    private ScheduledExecutorService scheduledExecutorService;

    public ForConnRunable(ScheduledExecutorService scheduledExecutorService) {
        this.scheduledExecutorService = scheduledExecutorService;
    }

    private static int i=0;

    @Override
    public void run() {
        if (i<3){
            i++;
            try {
                Thread.sleep(2000);
                System.out.println("======执行重连======");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }else{
            System.out.println("====记录;重连的异常=======重新连接==");
            scheduledExecutorService.shutdown();
        }
    }
}
